<link rel="stylesheet" href="themes/editor/default.css" />
<script charset="utf-8" type="text/javascript" src="js/editor/editor-min.js"></script>
<script charset="utf-8"  type="text/javascript" src="js/editor/editor_zh_CN.js"></script>
<h2>添加文件</h2>
<p>note: 文件大小要求小于2M</p>
<div class="upload">
	<div class="fitem">
		<label>上传:</label>
		<input id="fileId" type="hidden">
		<input class="ke-input-text" type="text" id="url" value="" readonly="readonly" /> <input type="button" id="uploadButton" value="选择文件" />
	</div>

</div>
<div id="otherInfo">
	<div class="fitem">
		<label>所在目录:</label>
		<input id="parentID" style="width:150px;">
	</div>
	<div class="fitem">
		<label>别名:</label>
		<input id="name" name="name" style="width:145px">
	</div>
	<div class="fitem">
		<label>可见性:</label>
		<input id="resourceLevel" name="level" style="width:150px">
	</div>
	<div class="fitem">
		<label>描述:</label>
		<textarea  id="desc" name="desc" style="width:200px"></textarea>
	</div>
	
	<a href="javascript:void(0)" class="easyui-linkbutton" onclick="javascript:addFileJs.update()">添加</a>
</div>

<div id="authPage">
	
</div>
<script type="text/javascript">
(function(addFileJs, $, undefined ) {
	addFileJs.init = function(){
		$('#otherInfo').hide();
		$('#authPage').hide();
		$('#parentID').combotree({
			url: 'dispatch/utility/folder/all',
		    required: true,
		    loadFilter: function(data){
		    	return jQuery.parseJSON(data.payload.value);
		    },
		});
		var uploadbutton = KindEditor.uploadbutton({
			button : KindEditor('#uploadButton'),
			 fieldName : 'cfile',
			 url :'file/upload?type=main',
			 afterUpload : function(data) {
				 //var payload = jQuery.parseJSON(data);
				 if(data.error == '0')
				{
					 $('#url').val(data.name);
					 $('#fileId').val(data.id);
					 $('#name').val(data.name);

					 $('#otherInfo').show();
				}else
				{
					$.messager.alert("上传错误",data.message);
				}
				 
			 },

		});
		 uploadbutton.fileBox.change(function(e) {
			 uploadbutton.submit();
		 });
		$('#resourceLevel').combobox({
				url:null,
				valueField:'value',
				textField:'name',
				multiple:false,
				panelHeight:'auto',
				data:[
				      {name:"公开",value:"Public",selected:true},
				      {name:"私有",value:"Private"}]
		});
		//loadData("dispatch/utility/folder/all",queryFolderResult,null);
	};
	
	function loadData(url,func,para){
		$.ajax({
	        type: "post",
	        url: url,
	        dataType:"json",
	        success: function (result) {
	        	func(result,para);
	        }
	        
	    });
	};
	addFileJs.update = function(){
    	var json = {};
    	json.name = $("#name").val();
    	json.parent = parseInt($('#parentID').combotree('getValue'));
    	json.description = $("#desc").val();
    	json.id = $("#fileId").val();
    	json.level = $('#resourceLevel').combobox('getValue');
		
    	var str = $.toJSON(json);
    	str = 'parameters='+str;
    	
		$.ajax({
            type: "post",
            url: 'dispatch/utility/file/update',
            dataType:"json",
            data: str,
            cache: false,
            success: function (result) {
            	var res = result.result;
                if(res == "SUCCESS")
                {
                	var message = "添加成功";
                	$.messager.alert('Success',message,'info',function(){
                		
                			var callback = fileActionJs.getCallBack();
                			if(callback == null)
                			{
                				var id = $("#fileId").val();
                				workbenchJs.open1('component/utility/viewResource.jsp?type=file&id='+id,this);
                			}else
                			{
                				callback(result);
                			}
                    		
                        });	
                	
                }else if(res == "COMPONENT_ERROR")
                {
                	$.messager.alert("Error",result.payload.value);
                }else
                {
                	$.messager.alert("Error",result.result);
                }
                
            }
            
        });
	}
}( window.addFileJs = window.addFileJs || {}, jQuery ));

    $(function(){
    	addFileJs.init();
    });
</script>
 <style type="text/css">
        .ftitle{
            font-size:14px;
            font-weight:bold;
            padding:5px 0;
            margin-bottom:10px;
            border-bottom:1px solid #ccc;
        }
        .fitem{
            margin-bottom:5px;
        }
        .fitem label{
            display:inline-block;
            width:80px;
        }
 </style>